package backup;

/**
 * @author kjysmu
 *
 */
/*
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;

import parameter.*;
import modules.*;
import functions.*;


public class LabeledUser
{
	Map<String,Map<String, Integer>> categoryCount = new HashMap<String,Map<String, Integer>>();
	public void SaveCategoryCount(String snstype){
		try{
			FileReader fr;
			if(snstype.equals("Facebook")){
				fr = new FileReader(Path.FACEBOOK_LABEL_RESULT_PATH);
			}else{
				fr = new FileReader(Path.TWITTER_LABEL_RESULT_PATH);
			}
			
			BufferedReader reader = new BufferedReader(fr);
	
			String line = "";
			String userID = "";
			
			while ((line = reader.readLine()) != null) {
				if(line.trim().isEmpty())
					continue;
				
				if(line.startsWith("// UserID: ")){
					userID = line.substring(line.lastIndexOf(" ")+1);
					categoryCount.put(userID, new HashMap<String, Integer>());
				}
				StringTokenizer st = new StringTokenizer(line, "\t");
				
				if( st.countTokens() == 7 ){
					String tk1 = st.nextToken();
					String tk2 = st.nextToken();
					String tk3 = st.nextToken();
					String tk4 = st.nextToken();
					String tk5 = st.nextToken();
					String tk6 = st.nextToken();
					String tk7 = st.nextToken();
					
	                String categoryMain1 = tk4.replaceAll(" ", "").replaceAll("/", "");
	                String category1 = tk5.replaceAll(" ", "").replaceAll("/", "");
	                String categoryMain2 = tk6.replaceAll(" ", "").replaceAll("/", "");
	                String category2 = tk7.replaceAll(" ", "").replaceAll("/", "");
					
					if(!tk4.equals("NONE") && !tk5.equals("NONE")){
						if(categoryCount.get(userID).containsKey(categoryMain1 + " " + category1))
							categoryCount.get(userID).put(categoryMain1 + " " + category1, categoryCount.get(userID).get(categoryMain1 + " " + category1) + 1 );
						else
							categoryCount.get(userID).put(categoryMain1 + " " + category1, 1);
					}
					if(!tk6.equals("NONE") && !tk7.equals("NONE")){
						if(!category1.equals(category2)){
							if(categoryCount.get(userID).containsKey(categoryMain2 + " " + category2))
								categoryCount.get(userID).put(categoryMain2 + " " + category2, categoryCount.get(userID).get(categoryMain2 + " " + category2) + 1 );
							else
								categoryCount.get(userID).put(categoryMain2 + " " + category2, 1);
						}
					}
					
				}
			
			}
			
			reader.close();
			fr.close();
				
			FileWriter fw;
			
			if(snstype.equals("Facebook")){
				 fw = new FileWriter(Path.FACEBOOK_LABEL_RESULT_COUNT_PATH);
			}else{
				 fw = new FileWriter(Path.TWITTER_LABEL_RESULT_COUNT_PATH);
			}
			
			BufferedWriter writer = new BufferedWriter(fw);
	
	    	for(Map.Entry<String, Map<String,Integer>> user : categoryCount.entrySet()){
	    		
	    		writer.write("ID: "+user.getKey());
	    		writer.newLine();
	    		
				IntValueComparator bvc = new IntValueComparator(user.getValue());
				TreeMap<String, Integer> tMap = new TreeMap<String, Integer>(bvc);
				tMap.putAll(user.getValue());
	    		
	        	for(Map.Entry<String, Integer> category : tMap.entrySet() ){
	        		writer.write(category.getKey() + "\t" + category.getValue());
	        		writer.newLine();
	
	        	}
	        	writer.newLine();
	
	    	}
	    	writer.close();
	    	fw.close();
		}catch(Exception e){
			e.printStackTrace();
		}

	}
	
	public Map<String, Map<String, Integer>> ReadCategoryCount(String filename){
		
		try{
		
			FileReader fr = new FileReader(filename);
			BufferedReader reader = new BufferedReader(fr);
			
			if(categoryCount == null)
				categoryCount = new HashMap<String, Map<String, Integer>>();
			
			String userid="";
			String line="";
			
			while ((line = reader.readLine()) != null) {
				
				if( line.startsWith("ID: ")){
					
					userid = line.split(" ")[1];
					categoryCount.put(userid, new HashMap<String, Integer>());
					
				}else if( !line.trim().isEmpty() ){
					
					StringTokenizer st = new StringTokenizer(line, "\t");
					
					String tk1 = st.nextToken();
					String tk2 = st.nextToken();
					
					categoryCount.get(userid).put(tk1, Integer.parseInt(tk2));
				}
					
			}
			
			reader.close();
			fr.close();
			
			return this.categoryCount;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
		
	}
	
	public Map<String, Map<String,Double>> GetUserCategoryFrequency (){
		
		if(categoryCount == null)
			return null;
		
		Map<String, Map<String,Double>> result = new HashMap<String, Map<String, Double>>();
		
    	for(Map.Entry<String, Map<String,Integer>> user : categoryCount.entrySet()){
    		
    		result.put(user.getKey(), new HashMap<String, Double>());
    		int totalCount = 0;
    		
        	for(Map.Entry<String, Integer> count : user.getValue().entrySet()){
        		totalCount += count.getValue();
        	}
        	
        	for(Map.Entry<String, Integer> category : user.getValue().entrySet()){
        		result.get(user.getKey()).put(category.getKey(), category.getValue() / (double)totalCount);
        		
        	}
        	
    	}
    	
    	return result;

	}
	
	public Map<String, Map<String,Double>> GetUserMainCategoryFrequency(){
		
		Map<String, Map<String, Double>> tempResults = GetUserCategoryFrequency();
		 
		Map<String, Map<String, Double>> result = new HashMap<String, Map<String, Double>>();
    	for(Map.Entry<String, Map<String,Double>> tempResult : tempResults.entrySet()){
    		
    		result.put(tempResult.getKey(), new HashMap<String, Double>());
        	for(Map.Entry<String, Double> frequency : tempResult.getValue().entrySet()){
        		String mainCategory = frequency.getKey().split(" ")[0];
        		if(!result.get(tempResult.getKey()).containsKey(mainCategory))
        			result.get(tempResult.getKey()).put(mainCategory, 0.0);
        		
        		result.get(tempResult.getKey()).put(mainCategory, result.get(tempResult.getKey()).get(mainCategory) + frequency.getValue());
        		
        	}
    	}

    	return result;
		
		
	}
	
}
*/
